using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TradeFlow.Server.Service;
using TradeFlow.Server.Dto;
using TradeFlow.Server.Models;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using TradeFlow.Server.Language;
using System.Reflection;

namespace TradeFlow.Web.Controllers
{
    /// <summary>
    /// 商业伙伴控制器
    /// </summary>
    [Authorize]
    public class JxPartnerController : Controller
    {
        private readonly JxPartnerService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public JxPartnerController(JxPartnerService service)
        {
            _service = service;
        }

        /// <summary>
        /// 商业伙伴管理首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 查询商业伙伴分页列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetPages([FromBody] JxPartnerPageParam param)
        {
            var result = await _service.GetPagesAsync(param);
            return Json(result);
        }

        /// <summary>
        /// 获取所有商业伙伴列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetList()
        {
            var result = await _service.GetListAsync();
            return Json(result);
        }

        /// <summary>
        /// 增加商业伙伴
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add([FromBody] JxPartner entity)
        {
            var result = await _service.AddAsync(entity);
            return Json(result);
        }

        /// <summary>
        /// 更新商业伙伴
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update([FromBody] JxPartner entity)
        {
            var result = await _service.UpdateAsync(entity);
            return Json(result);
        }

        /// <summary>
        /// 删除商业伙伴
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> Delete([FromBody] EntityBaseId ids)
        {
            var result = await _service.DeleteAsync(ids);
            return Json(result);
        }
    }
}